﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using Beetle.Web.Composite;
using System.Drawing;
using System.Web.UI.WebControls;

namespace Beetle.Web.UI.WebControls
{
    [TypeConverter(typeof(GridViewExtensionTypeConverter))]
    [Serializable]
    public class GridViewMouseOverExtension : ExtensionBase
    {
        #region IExtension<GridView> 成员

        public override void Attach(object owner)
        {
            GridView gv = owner as GridView;

            if (this.BgColor != Color.Empty)
            {
                if (gv != null)
                {
                    gv.RowDataBound += new System.Web.UI.WebControls.GridViewRowEventHandler(owner_RowDataBound);
                }
            }
        }

        void owner_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "this.oldColor=this.style.backgroundColor;this.style.backgroundColor='" + ColorTranslator.ToHtml(this.BgColor) + "';");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldColor;");
            }
        }
        #endregion

        private Color bgColor = Color.Empty;
        [TypeConverter(typeof(WebColorConverter))]
        [Category("公共属性")]
        [Description("当值为空时是否验证")]
        public Color BgColor
        {
            get
            {
                return this.bgColor;
            }

            set
            {
                this.bgColor = value;
            }
        }
    }
}
